<?php if (!defined("_ECRIRE_INC_VERSION")) return; ?>
<div id="edit_div">
    <form action="<?=generer_url_ecrire("radiodj_programs_schedule&day=#DAY")?>[&id_rubrique=(#ID_RUBRIQUE)]" method="post">
    <input type="hidden" value="" name="edit_record" class="edit_record" />
    <br />    
    <label for="id_rubrique">Название программы:</label>
    <select name="id_rubrique" class="id_rubrique">    
    [(#REM) Не забываем задать нужный id_rubrique в конфиге!!!]
    <BOUCLE_progrub(RUBRIQUES){tout}{id_rubrique?}{id_parent=#CONFIG{radiodj/IdRubriqueProgram}}>
        <option value="#ID_RUBRIQUE">#TITRE</option>
    </BOUCLE_progrub>
    </select>
    <br /><br />
    <label>Время начала:</label>    
    <select name="time_begin_hour" class="time_begin_hour">        
        <?php for($i = 0; $i < 24; $i++) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>        
    </select>
    <select name="time_begin_minute" class="time_begin_minute">        
        <?php for($i = 0; $i < 60; $i=$i+1) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>        
        <?php } ?>        
        <option value="59">59</option>
    </select>
    <label>Время окончания:</label>    
    <select name="time_end_hour" class="time_end_hour">        
        <?php for($i = 0; $i < 24; $i++) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>        
    </select>
    <select name="time_end_minute" class="time_end_minute">        
        <?php for($i = 0; $i < 60; $i=$i+1) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>        
        <?php } ?>
        <option value="59">59</option>        
    </select><br /><br />
    <div style="text-align: center;">    
    <input type="submit" value="Сохранить" />
    <input type="button" value="Отмена" onclick="$('tr.edit_tr').remove();" />
    </div>
    </form>
</div>

<script>
    $(document).ready(function(){
        $("#edit_div").hide();
                
        $(".edit_schedule").click(function(){
            $("tr.edit_tr").remove();
            
            if (!$(this).hasClass('toogle')) {
            $(this).addClass('toogle');
            
            var edit_tr = $(this).parent().parent();
            var edit_div_html = $("#edit_div").html();            
            var form_text_html = '<tr class="edit_tr"><td colspan="5">'+edit_div_html+'</td></tr>';                
                //form_text_html.replace('%id_schedule%', edit_tr.find('div.id_schedule').text());
            var id_rubrique = edit_tr.find('input.id_rubrique_input').val();
            var time_begin_hour = edit_tr.find('td.time_begin').text().split(':')[0];
                time_begin_hour = parseInt(time_begin_hour, 10);                 
            var time_begin_minute = edit_tr.find('td.time_begin').text().split(':')[1];
                time_begin_minute = parseInt(time_begin_minute, 10);                
            var time_end_hour = edit_tr.find('td.time_end').text().split(':')[0];                
                time_end_hour = parseInt(time_end_hour, 10);
            var time_end_minute = edit_tr.find('td.time_end').text().split(':')[1];
                time_end_minute = parseInt(time_end_minute, 10);
            
            edit_tr_form = edit_tr.after(form_text_html).next();
            edit_tr_form.find("select.id_rubrique option[value="+id_rubrique+"]").attr('selected', 'selected');
            edit_tr_form.find("select.time_begin_hour option[value="+time_begin_hour+"]").attr('selected', 'selected');
            edit_tr_form.find("select.time_begin_minute option[value="+time_begin_minute+"]").attr('selected', 'selected');
            edit_tr_form.find("select.time_end_hour option[value="+time_end_hour+"]").attr('selected', 'selected');
            edit_tr_form.find("select.time_end_minute option[value="+time_end_minute+"]").attr('selected', 'selected');            
            //edit_tr_form.html(edit_tr_form.html().replace('%id_schedule%', edit_tr.find('div.id_schedule').text()));            
            edit_tr_form.find('input.edit_record').val(edit_tr.find('input.id_schedule_input').val());                        
            } else {
                $(this).removeClass('toogle');
            }
        });
        
    });
</script>

<div class="fiche_objet">
<form action="<?=generer_url_ecrire("radiodj_programs_schedule&day=#DAY")?>[&id_rubrique=(#ID_RUBRIQUE)]" method="post">
<input type="hidden" value="yes" name="new_record"/>
<h4>Добавление новой записи</h4>
    <label for="id_rubrique">Название программы:</label>
    <select name="id_rubrique" class="id_rubrique">
    [(#REM) Не забываем задать нужный id_rubrique в конфиге!!!]
    <BOUCLE_progrub2(RUBRIQUES){tout}{id_rubrique?}{id_parent=#CONFIG{radiodj/IdRubriqueProgram}}>
        <option value="#ID_RUBRIQUE">#TITRE</option>
    </BOUCLE_progrub2>
        <?php foreach($djs as $dj) { ?>
        <option <?=_request('id_rubrique')==$dj['id_rubrique']? 'selected' : ''?> value="<?=$dj['id_rubrique']?>"><?=$dj['nom']?></option>
        <?php } ?>
    </select>
    <br /><br />
    <label>Время начала:</label>    
    <select name="time_begin_hour">        
        <?php for($i = 0; $i < 24; $i++) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>        
    </select>
    <select name="time_begin_minute">        
        <?php for($i = 0; $i < 60; $i=$i+1) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>
        <option value="59">59</option>        
    </select>
    <label>Время окончания:</label>    
    <select name="time_end_hour">        
        <?php for($i = 0; $i < 24; $i++) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>        
    </select>
    <select name="time_end_minute">        
        <?php for($i = 0; $i < 60; $i=$i+1) { ?>
        <option value="<?=$i?>"><?=sprintf("%'02d", $i)?></option>
        <?php } ?>
        <option value="59">59</option>        
    </select><br />
<div style="text-align: center;">
<input type="submit" value="Добавить" />
</div>
</form>
</div>
 
<div class='cadre_padding fiche_objet'>
<B_records>
<table cellpadding="0" cellspacing="0" class='arial2' style='width: 100%;'>
<tr class='titrem'>    
    <th>Название программы</th>
    <th>Время начала</th>    
    <th>Время окончания</th>    
    <th></th>        
    <th></th>
</tr>
<BOUCLE_records(RADIODJ_PROGRAMS_SCHEDULE rubriques){day?}{id_rubrique?}{par time_begin}>
    <tr class='tr_liste'>    
    <input class="id_rubrique_input" type="hidden" value="#ID_RUBRIQUE" />
    <input class="id_schedule_input" type="hidden" value="#ID_PROGRAMS_SCHEDULE" />
    <td class="arial2">#TITRE</td>
    <td class="arial2 time_begin">#TIME_BEGIN</td>    
    <td class="arial2 time_end">#TIME_END</td>
    <td class="arial2"><a class="edit_schedule" href="#">Редактировать</a></td>
    <td class="arial2"><a href="<?=generer_url_ecrire("radiodj_programs_schedule")?>&del_schedule_row=#ID_PROGRAMS_SCHEDULE&day=#DAY[&id_rubrique=(#ID_RUBRIQUE)]">Удалить</a></td>
    </tr>
</BOUCLE_records>
</table>
</B_records>
    Нет записей!
<//B_records>
</div>